//
//  SettingViewController.m
//  iExpense
//
//  Created by JackyLiang on 09-7-12.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "SettingViewController.h"
#import "ExportToViewController.h"
#import "CurrencyViewController.h"


@implementation SettingViewController
@synthesize settingsTable;
@synthesize settingsParametersList;
@synthesize settingsHelpAboutList;

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	self.title = @"Settings";
	
	settingsParametersList = [[NSArray alloc] initWithObjects:@"Export To", @"Default Currency", @"Default Category",
							@"Default Subcategory", @"Default Payee", @"Password Protection", nil];
	
	settingsHelpAboutList = [[NSArray alloc] initWithObjects:@"Help", @"About iExpense", nil];
}


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}

#pragma mark Table view methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
	if (section == 0)
		return [self.settingsParametersList count];
	else
		return [self.settingsHelpAboutList count];
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
    }
    
	// Configure the cell.
	if (indexPath.section == 0) {
		cell.textLabel.text = [settingsParametersList objectAtIndex:indexPath.row];
		switch (indexPath.row) {
			case 0:
				cell.detailTextLabel.text = @"zyan.wu@ni.com";
				break;
			case 1:
				cell.detailTextLabel.text = @"USD";
				break;
			case 2:
				cell.detailTextLabel.text = @"Meal";
				break;
			case 3:
				cell.detailTextLabel.text = @"Dinner";
				break;
			case 4:
				cell.detailTextLabel.text = @"Pizza Hut";
				break;
			case 5:
				cell.detailTextLabel.text = @"ON";
				break;
			default:
				break;
		}
	}
	else {
		cell.textLabel.text = [settingsHelpAboutList objectAtIndex:indexPath.row];
	}
	
	cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
	
    return cell;
}

// Override to support row selection in the table view.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	
    // Navigation logic may go here -- for example, create and push another view controller.
	// AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil];
	// [self.navigationController pushViewController:anotherViewController animated:YES];
	// [anotherViewController release];
	[settingsTable deselectRowAtIndexPath:indexPath animated:NO];
	
	if (indexPath.section == 0) {
		if (indexPath.row == 0) {
			ExportToViewController *controller = [[ExportToViewController alloc] initWithNibName:@"ExportToView" bundle:nil];
			//controller.editingItem = self.editingItem;
			[self.navigationController pushViewController:controller animated:YES];
			[controller release];
		}
		else if (indexPath.row == 1) {
			CurrencyViewController *controller = [[CurrencyViewController alloc] initWithNibName:@"CurrencyView" bundle:nil];
			//controller.editingItem = self.editingItem;
			//controller.row = indexPath.row;
			[self.navigationController pushViewController:controller animated:YES];
			[controller release];		
		}
		else if (indexPath.row == 2) {
			//RepeatViewController *controller = [[RepeatViewController alloc] initWithNibName:@"RepeatViewController" bundle:nil];
			//controller.editingItem = self.editingItem;
			//[self.navigationController pushViewController:controller animated:YES];
			//[controller release];		
		}
		else if (indexPath.row == 3) {
			//SoundAlertTimeViewController *controller = [[SoundAlertTimeViewController alloc] initWithNibName:@"SoundAlertTimeViewController" bundle:nil];
			//controller.editingItem = self.editingItem;
			//controller.row = indexPath.row;
			//[self.navigationController pushViewController:controller animated:YES];
			//[controller release];
		}
		else if (indexPath.row == 4) {
			//SoundAlertTimeViewController *controller = [[SoundAlertTimeViewController alloc] initWithNibName:@"SoundAlertTimeViewController" bundle:nil];
			//controller.editingItem = self.editingItem;
			//controller.row = indexPath.row;
			//[self.navigationController pushViewController:controller animated:YES];
			//[controller release];
		}
		else if (indexPath.row == 5) {
			//SoundAlertTimeViewController *controller = [[SoundAlertTimeViewController alloc] initWithNibName:@"SoundAlertTimeViewController" bundle:nil];
			//controller.editingItem = self.editingItem;
			//controller.row = indexPath.row;
			//[self.navigationController pushViewController:controller animated:YES];
			//[controller release];
		}
		else {
			// will never happen here
		}
	}
	else {
		if (indexPath.row == 0) {
			//ExportToViewController *controller = [[ExportToViewController alloc] initWithNibName:@"ExportToView" bundle:nil];
			//controller.editingItem = self.editingItem;
			//[self.navigationController pushViewController:controller animated:YES];
			//[controller release];
		}
		else if (indexPath.row == 1) {
			//TimePickerViewController *controller = [[TimePickerViewController alloc] initWithNibName:@"TimePickerViewController" bundle:nil];
			//controller.editingItem = self.editingItem;
			//controller.row = indexPath.row;
			//[self.navigationController pushViewController:controller animated:YES];
			//[controller release];		
		}
		else {
			// will never happen here
		}
	}
}


- (void)dealloc {
	[settingsTable release];
	[settingsParametersList release];
	[settingsHelpAboutList release];
    [super dealloc];
}


@end
